package com.example.zhugenew.fragment;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mymvplibrary.ui.fragment.BaseMvpFramgent;
import com.example.zhugenew.R;
import com.example.zhugenew.adapter.ImportantAdapter;
import com.example.zhugenew.bean.ImportantBean;
import com.example.zhugenew.concation.MainConations;
import com.example.zhugenew.model.HomeModel;
import com.example.zhugenew.presenter.HomePresenter;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;

public class ImportantFragment<T> extends BaseMvpFramgent<MainConations.MainView, HomeModel, HomePresenter<T>> implements MainConations.MainView<T> {

    @BindView(R.id.im_recl)
    RecyclerView imRecl;
    @BindView(R.id.im_smart)
    SmartRefreshLayout imSmart;
    private ArrayList<ImportantBean.ListBean> listBeans;
    private ImportantAdapter importantAdapter;

    @Override
    protected HomePresenter<T> createPresenter() {
        return new HomePresenter();
    }

    @Override
    protected void initEvent() {
        imRecl.setLayoutManager(new LinearLayoutManager(context));
        imRecl.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));
        listBeans = new ArrayList<>();
        importantAdapter = new ImportantAdapter(listBeans, context, R.layout.layout_recommend_item);
        imRecl.setAdapter(importantAdapter);
        HashMap<String, Object> map = new HashMap<>();
        map.put("modular","zgrb");
        map.put("city","bj");
        mPerter.getData("contentService/v1/News/appNewsList",0,map);
    }

    @Override
    protected int createLayoutId() {
        return R.layout.fragment_important;
    }

    @Override
    public void showList(T t, int type) {
        if (type==0){
            ImportantBean importantBean = new Gson().fromJson((JsonElement) t, ImportantBean.class);
            listBeans.addAll(importantBean.getList());
            importantAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void showError(String error, int code) {

    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }
}